<template>
    <div >
      <h2>任务管理</h2>
        <Common
            addTitle="添加任务"
            type="task"
             :users="this.users"
             @addEvaluate="addEvaluate"
             :tableDataProp="this.data"
        ></Common>
    </div>
  </template>
  
  <script>
  import Common from '../../components/performance/common.vue'
  import { getUserList} from '@/api/staffs'
  import {addTask,getTask} from '@/api/task'

  export default {
    name: 'task',
    components:{
        Common
    },
    data() {
      return {
        username:"",
        users:[],
        data:[]
      }
    },
    mounted(){
        this.username = localStorage.getItem("uname");
        this.empNo = localStorage.getItem("empNo")*1;
        this.getUserListFn();
        this.getTaskList();
    } ,
    methods:{
      async addEvaluate(payload){
            console.log("任务数据是？",payload);
            let { title,
            content,
            taskType:type,
            dieDate:endDate} = payload;
            /* 
            title content empNo type endDate
            */
          let res =  await addTask({ title,
            content,
            empNo:this.empNo,
            empName:this.username,
            type,
            endDate})

            console.log("添加任务返还的结果是",res);
            if(res.data.code===200){
                this.getTaskList();
            }


      },

      async getUserListFn(){
         let {data:{rows}} =  await getUserList();
          let filterRows = rows.filter(item=>item.emp_no!=this.empNo);
         this.users = filterRows;
      },
      async getTaskList(){
         let {data:{rows}} =  await getTask();
         console.log("task:??",rows);
          this.data = rows;
         
      }


    }
  }
  </script>
  
  <style>
  
  </style>
  